package com.tyk.bookstore.back.system.valid.provider;

import com.tyk.bookstore.back.system.model.query.MenuUpdateQuery;
import com.tyk.bookstore.back.system.model.type.MenuType;
import com.tyk.bookstore.back.system.valid.group.TypeEqualsMenuItem;
import com.tyk.bookstore.back.system.valid.group.TypeEqualsSubMenu;
import org.hibernate.validator.spi.group.DefaultGroupSequenceProvider;

import java.util.ArrayList;
import java.util.List;

public class UpdateMenuQueryGroupSequenceProvider implements DefaultGroupSequenceProvider<MenuUpdateQuery> {
    @Override
    public List<Class<?>> getValidationGroups(MenuUpdateQuery query) {
        List<Class<?>> groupSequenceList = new ArrayList<>();
        groupSequenceList.add(MenuUpdateQuery.class);
        if(query != null) {
            if(query.getType().equals(MenuType.SUB_MENU)) {
                groupSequenceList.add(TypeEqualsSubMenu.class);
            }
            if(query.getType().equals(MenuType.MENU_ITEM)) {
                groupSequenceList.add(TypeEqualsMenuItem.class);
            }
        }

        return groupSequenceList;
    }
}
